﻿using CameraParentClassLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


namespace Dahua
{
    public class Dahua : CameraParent
    {
        /// <summary>
        /// 定时器
        /// </summary>
        Timer timer = null;

        private int _delay = 35;//延时时间
        /// <summary>
        /// 延时
        /// </summary>
        public override int DelayTime
        {
            get => _delay;
            set
            {
                _delay = value;
                //改变定时器的间隔
                if (timer != null)
                {
                    timer.Change(0, _delay);//延时时间
                }
            }
        }

        public Dahua()
        {
            BrandName = "大华";
        }

        public override void OpenCamera()
        {
            base.OpenCamera();
            SetLabelText?.Invoke("打开相机");
            //注册回调函数
            TimerCallback timerCallback = new TimerCallback(FunctionCallBack);
            //实例化定时器
            timer = new Timer(timerCallback, null, 0, DelayTime);
        }

        public void FunctionCallBack(object obj)
        {
            switch (CameraWorkState)
            {
                case CamerWork.None:
                    break;
                case CamerWork.采集一张:
                    SetLabelText?.Invoke(DateTime.Now.ToString());
                    CameraWorkState = CamerWork.None;
                    break;
                case CamerWork.连续采集:
                    SetLabelText?.Invoke(DateTime.Now.ToString());
                    break;
            }
        }

        public override void CloseCamera()
        {
            base.CloseCamera();
            timer.Dispose();//释放相机对象
            SetLabelText?.Invoke("关闭相机");
        }

    }
}
